<script setup lang="ts">
import type { PropType } from 'vue';

defineOptions({ name: 'Query' });
defineProps({
  modelValue: {
    type: Object as PropType<ModelValueType>,
    required: true,
  },
});

const emit = defineEmits(['update:modelValue', 'queryData', 'resetQuery']);

interface ModelValueType {
  name: string;
  phone: string;
  createTime: any;
}

const disabledFutureDate = (time: any) => {
  const today = new Date()
  today.setHours(0, 0, 0, 0)
  return time.getTime() > today.getTime()
}

const onQueryData = () => {
  emit('queryData');
};
const resetQuery = () => {
  emit('resetQuery',)
}
</script>
<template>
  <section class="w-full bg-[#fff]">
    <el-form :inline="true"
      class="auth-web-search-form w-full border-b border-color:#DCDFE6 after:content-[''] mb-[15px] after:clear-both after:block">
      <el-form-item :label="$t('studentMgr.nameTxt')">
        <el-input v-model="modelValue.name" :maxlength="50" clearable style="width: 100%;"
          :placeholder="$t('common.inputPhTxt', [$t('studentMgr.nameTxt')])" />
      </el-form-item>
      <el-form-item :label="$t('common.phoneTxt')">
        <el-input v-model="modelValue.phone" clearable style="width: 100%;" maxlength="11"
          :placeholder="$t('common.inputPhTxt', [$t('common.phoneTxt')])" />
      </el-form-item>
      <el-form-item :label="$t('common.createTimeTxt')" style="min-width:280px">
        <el-date-picker v-model="modelValue.createTime" :disabled-date="disabledFutureDate" type="daterange"
          :range-separator="$t('common.rangeSeparatorTxt')" style="width: 100%" value-format="YYYY-MM-DD HH:mm:ss"
          :unlink-panels="true" :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)]"
          :start-placeholder="$t('common.startTimeTxt')" :end-placeholder="$t('common.endTimeTxt')" />
      </el-form-item>
      <el-form-item label="" class="float-right" style="width: 150px;">
        <div class="w-full flex justify-end">
          <el-button class="mb-[10px]" @click="resetQuery">{{ $t('common.resetTxt') }}</el-button>
          <el-button class="mb-[10px]" type="primary" @click="onQueryData">{{ $t('common.searchTxt') }}</el-button>
        </div>
      </el-form-item>
    </el-form>
  </section>
</template>
<style lang="scss" scoped>
:deep(.el-form--inline .el-form-item) {
  margin-right: 24px;
  width: calc((100% - 72px)/4);

  &:nth-of-type(4n),
  &:last-of-type {
    margin-right: 0px;
  }
}

:deep(.el-form-item__label) {
  color: #595959;
  padding-right: 12px;
}
</style>
